﻿// =================================================================== 
// 项目说明
//====================================================================
// lsc。@Copy Right 2019
// 文件： GovMenu.cs
// 项目名称：斑马车务
// 创建时间：2019-01-09
// 负责人：lsc
// ===================================================================
using System;
using System.Data;
using System.Collections.Generic;
using Dapper.Extensions;
using CGT.Infrastructure.Entity;
using CGT.Infrastructure.Repository;
using CGT.Infrastructure.Dto;

namespace CGT.Infrastructure.Service
{

    /// <summary>
    ///菜单
    /// </summary>
    public class GovMenuService
    {
        protected GovMenuRepository repository;

        public GovMenuService()
        {
            repository = new GovMenuRepository();
        }

        #region 增删改查

        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public object Insert(GovMenu entity) { return repository.Insert(entity); }

        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public object Insert(List<GovMenu> entitys) { return repository.Insert(entitys); }

        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public bool Update(GovMenu entity) { return repository.Update(entity); }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public bool Delete(GovMenu entity) { return repository.Delete(entity); }

        /// <summary>
        /// 删除所有
        /// </summary>
        /// <returns></returns>
        public bool DeleteAll() { return repository.DeleteAll(); }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="primaryKey">主键</param>
        /// <returns></returns>
        public bool Delete(int primaryKey) { return repository.Delete(primaryKey); }

        /// <summary>
        /// 查询单个实体
        /// </summary>
        /// <param name="primaryKey">主键</param>
        /// <returns></returns>
        public GovMenu SingleOrDefault(object primaryKey) { return repository.SingleOrDefault(primaryKey); }


        /// <summary>
        /// 查询单个实体,如果存在多条则引发异常
        /// </summary>
        /// <param name="primaryKey">主键</param>
        /// <returns></returns>
        public GovMenu Single(object primaryKey) { return repository.Single(primaryKey); }

        /// <summary>
        /// 查询所有
        /// </summary>
        /// <returns></returns>
        public List<GovMenu> QueryAll()
        {
            return repository.QueryAll();
        }

        /// <summary>
        /// 查询有效
        /// </summary>
        /// <returns></returns>
        public List<GovMenu> GetValidList()
        {
            return repository.GetValidList();
        }

        /// <summary>
        /// 获取父级菜单
        /// </summary>
        /// <returns></returns>
        public List<GovMenu> GetParentList()
        {
            return repository.GetParentList();
        }

        /// <summary>
        /// 编码是否重复
        /// </summary>
        /// <returns></returns>
        public bool CheckMenuCode(int code)
        {
            return repository.CheckMenuCode(code);
        }

        /// <summary>
        /// 获取菜单并显示根据角色ID获取已关联的菜单
        /// </summary>
        /// <returns></returns>
        public List<GovRoleMenuRelaDto> GetRoleMenuRelaList(int roleId)
        {
            return repository.GetRoleMenuRelaList(roleId);
        }

        /// <summary>
        /// 根据角色ID获取菜单
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns></returns>
        public List<GovMenu> GetUserMenuList(int roleId)
        {
            return repository.GetUserMenuList(roleId);
        }

        /// <summary>
        /// 根据角色ID、菜单编码获取菜单信息
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="menuCode"></param>
        /// <returns></returns>
        public GovMenu GetUserMenuByRoleIdMenuCode(int roleId, int menuCode)
        {
            return repository.GetUserMenuByRoleIdMenuCode(roleId, menuCode);
        }

        /// <summary>
        /// 根据菜单编码获取菜单信息
        /// </summary>
        /// <returns></returns>
        public GovMenu GetGovMenuByCode(int code)
        {
            return repository.GetGovMenuByCode(code);
        }

        /// <summary>
        /// 删除父级下的所有子菜单
        /// </summary>
        /// <param name="menuId"></param>
        /// <returns></returns>
        public bool DelGovMenuByParentId(int parentId)
        {
            return repository.DelGovMenuByParentId(parentId);
        }
        #endregion
    }

}